// 计算距离
export const getDistance = function(lat1, lng1, lat2, lng2) { // 当前的纬度，当前的经度，接口拿到的纬度，接口拿到的经度
	var radLat1 = lat1 * Math.PI / 180.0;
	var radLat2 = lat2 * Math.PI / 180.0;
	var a = radLat1 - radLat2;
	var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	// 输出为米
	s = Math.round(s * 10000) / 10;
	return s;
}

// 比较时间大小
// 如果time2大于time1 返回true 否则 返回false
export const compareTime = function(time1, time2, type) {
	let compareRes = false
	if (type == 'sbDk') {
		if (time_to_sec(time2) - time_to_sec(time1) > 59) {
			compareRes = true;
		} else {
			compareRes = false;
		}
	} else if (type == 'xbDk') {
		if (time_to_sec(time2) - time_to_sec(time1) > 0) {
			compareRes = true;
		} else {
			compareRes = false;
		}
	} else if (type == 'isLateLong') {
		if (time_to_sec(time2) - time_to_sec(time1) > 3659) {
			compareRes = true;
		} else {
			compareRes = false;
		}
	} else {
		if (time_to_sec(time2) - time_to_sec(time1) < 15) {
			compareRes = true;
		} else {
			compareRes = false;
		}
	}
	return compareRes
}

//将时分秒转为时间戳
export const time_to_sec = function(time) {
	if (time !== null) {
		var s = "";
		var hour = time.split(":")[0];
		var min = time.split(":")[1];
		var sec = time.split(":")[2];
		s = Number(hour * 3600) + Number(min * 60) + Number(sec);
		return s;
	}
}

// 获取当前时分秒
export const getNowTime = function() {
	var now = new Date();
	var hour = now.getHours(); //得到小时
	var minu = now.getMinutes(); //得到分钟
	var sec = now.getSeconds(); //得到秒
	var MS = now.getMilliseconds(); //获取毫秒
	if (hour < 10) hour = "0" + hour;
	if (minu < 10) minu = "0" + minu;
	if (sec < 10) sec = "0" + sec;
	var time = "";
	let nowTime = hour + ":" + minu + ":" + sec;
	return nowTime
}
